import JSEncrypt from 'jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQ9Ki9vhooYHY6U0cQPrMszetyrLmsjS6H3TuezxEFqYh4kBPaRBb6bWytpUm56rgDBkkPFUsslXbDGsfSrGkksrZ8rn075YIoCsdKgqOOoz/WgKNCSLY4OVT4f2zl0P2XUrd8AoEazfy5VU/anABnh+8kJVXi6Cby3lbRjaTL1QIDAQAB'
const privateKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJD0qL2+GihgdjpTRxA+syzN63KsuayNLofdO57PEQWpiHiQE9pEFvptbK2lSbnquAMGSQ8VSyyVdsMax9KsaSSytnyufTvlgigKx0qCo46jP9aAo0JItjg5VPh/bOXQ/ZdSt3wCgRrN/LlVT9qcAGeH7yQlVeLoJvLeVtGNpMvVAgMBAAECgYAvwnyqb608qnOpyfB7GL1+QKaX1PMkOCwhlbHkJENugyo01vvDiXWss0sAd5owCHbygCqoLpLjMKe9puA5uJa3gjgjf87ZYGYs+IZkb4qJ4LCrIB2+eGJG1kPPZfLcPcn+sqEkB2gBwOu2YNCIi80SV+k3XtehnREpJkbWHhS3QQJBANLpIuIfPBHUrBce8kbNR8PYAgsZqOwO1Nr5qWPUJORUOL/h+SmNndMu4DH5XrFLXnwuBxUOHfc043DluVodWVECQQCv8eSzQ7mUNST+axMs0/jM21eV7cXRu1m8PwBpna7ugh8OIpnURIgmDFL8D5s/WXjbb44MM7Q9dwHoJfvqIelFAkAMq4a18MxqAc2oweoqCLDz+ej9g7gbHjT5RqA/aAIjWU/jbw7JyUEe66T6O5HNssplSVqRkDyKmjnDkXlWCYdRAkAo4HAb3e4tqrMvkLzhu1Wgco1EvfspoPdWLuTvpLzRmNWSOSO4FzvyawaUnSOacjUL9jzwRMrpRM7imoCOgtZpAkEAj/hbVqjN8ul5cTWLhfPbMtIYghkOmBNrlvUb4vgIouXAfYcA4FQ/48MnsHPRyY/3CJTcRVT3kbldT69jIGqxHg=='

// 加密
export function encrypt(txt) {
    const encryptor = new JSEncrypt()
    encryptor.setPublicKey(publicKey) // 设置公钥
    return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
    const encryptor = new JSEncrypt()
    encryptor.setPrivateKey(privateKey) // 设置私钥
    return encryptor.decrypt(txt) // 对数据进行解密
}